<template>
  <div class="main-container">
    <!-- 头部 -->
    <div class="main-header por">
      <img :src="shopdata.pics ? shopdata.pics[0] : ''" />
      <div class="main-header-cale poa" @click="openbulletin()">
        <h3 class="main-title">{{ shopdata.name }}</h3>
        <p>
          <span>
            <van-rate
              :size="20"
              color="#ffd21e"
              void-icon="star"
              void-color="#ffd21e"
              :count="4.5"
            />
            {{ shopdata.score }}
          </span>
          <span>月销{{ shopdata.sellCount }}</span>
          <span>配送约{{ shopdata.deliveryTime }}分钟</span>
        </p>
        <ul class="supports">
          <li v-for="item in shopdata.supports" :key="item">{{ item }}</li>
        </ul>
        <p class="main-bulletin">公告：{{ shopdata.bulletin }}</p>
        <img :src="shopdata.avatar" alt="" class="main-avatar" />
      </div>
    </div>
    <!-- 主体部分 -->
    <div class="main-content">
      <!-- 结算商品弹出框 -->
      <van-popup
        v-model="show"
        round
        position="bottom"
        :style="{ height: '58%' }"
        @click-overlay="show = false"
      >
        <div class="goods-right">
          <div
            v-for="fooditem in selectedData"
            :key="fooditem.id"
            class="goods-conts"
          >
            <img :src="fooditem.imgUrl" @click="jumpgoodsabout(fooditem)" />
            <div class="goods-Desc df fdc jcsb">
              <h4 class="h4" @click="jumpgoodsabout(fooditem)">
                {{ fooditem.name }}
              </h4>
              <div class="fooditem-sellCount df">
                <p class="fooditem-p">月售{{ fooditem.sellCount }}</p>
                <p>好评度{{ fooditem.rating }}%</p>
              </div>
              <div class="stepper df jcsb">
                <p class="fooditem-price">￥{{ fooditem.price }}</p>
                <!-- 步进器 -->
                <p>
                  <van-stepper
                    v-model="fooditem.count"
                    theme="round"
                    min="0"
                    @minus="changeclose()"
                  />
                </p>
              </div>
            </div>
          </div>
        </div>
      </van-popup>

      <!-- 右边内容导航   -->
      <div class="main-nav">
        <van-tabs color="#f2c53d" line-width="30px" v-model="active">
          <van-tab
            v-for="item in tabsData"
            :key="item.path"
            :title="item.title"
            :to="item.path"
            :name="item.path"
          ></van-tab>
        </van-tabs>
      </div>

      <!-- 二级路由内容出口 -->
      <div class="main-body">
        <router-view></router-view>
      </div>

      <!-- 底部的购物车 -->
      <div class="main-footer df jcsb">
        <!-- 左侧 -->
        <div class="main-footer-left df fdc jcc" :style="`${totalprice>= 50?'color:#fff':'color:#999999'}`">
          <p class="p1"><van-icon name="phone" /></p>
          <p>联系商家</p>
        </div>
        <!-- 中间 -->
        <div class="main-footer-middle f1 df aic" @click="openpopup">
          <div
            class="shopcar df jcc aic"
            :style="`${totalprice>= 50?'background-color:#ffc300':'background-color:#999999'}`"
          >
            <van-badge :content="totalcount" :color="`${totalprice>= 50?'#f00':'#999999'}`">
              <div class="child"><van-icon name="cart" /></div>
            </van-badge>
          </div>
          <div class="shopprice">
            <div class="df aic">
              <span class="w">￥</span>
              <p class="price">{{ totalprice }}</p>
            </div>
            <p>另需配送配{{ psfprice }}￥元 &nbsp|&nbsp 50元起送</p>
          </div>
        </div>
        <!-- 右侧 -->
        <div class="main-footer-right" v-if="`${psfprice == 50}`" :style="`${totalprice>= 50?'background-color:#ffc300':'background-color:#999999'}`">
          <p>去结算</p>
        </div>
      </div>

      <!-- 蒙层 -->
      <van-overlay :show="show1" @click="show1 = false" class="overlay">
        <div class="title-wrap">
          <h4>{{ shopdata.name }}</h4>
          <van-rate
            v-model="value"
            :count="5"
            class="van-rate"
            color="#ffd21e"
            gutter="10px"
          />
          <div class="youhui-wrap">
            <div class="youhui"></div>
            <span>优惠信息</span>
            <div class="youhui"></div>
          </div>
        </div>
        <div>
          <p
            class="overlay-supports"
            v-for="(item, index) in shopdata.supports"
            :key="index"
          >
            {{ item }}
          </p>
        </div>

        <div class="bulletin-wrap">
          <div class="youhui-wrap">
            <div class="youhui"></div>
            <span>商家公告</span>
            <div class="youhui"></div>
          </div>
          <p class="bulletin">{{ shopdata.bulletin }}</p>
        </div>
      </van-overlay>
    </div>
  </div>
</template>

<script lang="ts">
import { Vue, Component, Prop, Watch } from "vue-property-decorator";
import { mapState, mapActions, mapGetters } from "vuex";

interface INav {
  title: string;
  path: string;
}

@Component({
  computed: {
    ...mapState(["shopdata", "color"]),
    ...mapGetters(["selectedData", "totalcount", "totalprice", "psfprice"]),
  },

  methods: {
    ...mapActions(["get_shop_data"]),
  },
})
export default class Main extends Vue {
  active: string = this.$route.path;
  get_shop_data: any;
  get_goods_about: any;
  shopdata: any;
  show: boolean = false;
  show1: boolean = false;
  value: number = 5;
  selectedData: any;
  totalprice:any;
  tabsData: Array<INav> = [
    { title: "商品", path: "/home/goods" },
    { title: "评价", path: "/home/comment" },
    { title: "商家", path: "/home/shop" },
  ];
  // 点击打开蒙层
  openbulletin() {
    this.show1 = true;
  }
  //点击打开购物车
  openpopup() {
    if (this.totalprice<50) {
      this.show = false;
    } else {
      this.show = true;
    }
  }
  // 减少商品，商品为0时，关闭打开的购物车
  changeclose() {
    let changeclose = this.selectedData.every((item: any) => {
      return this.selectedData.length == 1 && item.count == 1;
    });
    this.show = !changeclose;
  }

  // 加载拿数据
  created() {
    this.get_shop_data();
  }
}
</script>

<style lang="scss" scoped>
.main-container {
  height: 100vh;
  .main-header {
    position: relative;
    height: 200px;
    background-color: #ccc;
    img {
      width: 100%;
      height: 100%;
      filter: blur(5px);
    }
    .main-header-cale {
      position: absolute;
      height: 150px;
      width: 100%;
      border-radius: 15px 15px 0 0;
      background-color: #fff;
      bottom: 0;
      padding: 0 15px;
      box-sizing: border-box;
      .main-avatar {
        position: absolute;
        width: 80px;
        height: 80px;
        top: -10px;
        right: 10px;
        border-radius: 10px;
        filter: blur(0px);
      }
      .main-title {
        margin: 20px 0 0 0;
        font-size: 20px;
      }
      p {
        color: #aaa;
        margin: 5px 0;
        span {
          display: inline-block;
          margin-right: 15px;
        }
      }
      .supports {
        width: 100%;
        height: 50px;
        display: flex;
        flex-wrap: wrap;
        li {
          padding: 2px 6px;
          margin: 2px 6px;
          height: 18px;
          font-size: 12px;
          line-height: 18px;
          border: 1px solid #f6d4cc;
          border-radius: 3px;
          background-color: #fef1f4;
          color: #fb5a46;
        }
      }
    }
  }
  .main-content {
    display: flex;
    flex-direction: column;
    height: 100vh;
    .main-nav {
      font-size: 20px !important;
    }
    .main-body {
      flex: 1;
      overflow-y: auto;
    }
  }
  .main-footer {
    position: fixed;
    width: 92%;
    height: 50px;
    background-color: #000;
    border-radius: 25px;
    bottom: 10px;
    right: 50%;
    transform: translate(50%);
    z-index: 2222;
  }
  .main-bulletin {
    color: #919191;
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}

::v-deep .van-tab {
  font-size: 16px;
}

.overlay {
  padding: 30px 30px;
  color: #fff;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  background-color: rgba(0, 0, 0, 0.8);
  .title-wrap {
    display: flex;
    flex-direction: column;
    font-size: 20px;
  }
  .bulletin-wrap {
    height: 35%;
    .bulletin {
      font-size: 18px;
      padding-top: 20px;
      line-height: 28px;
    }
  }

  .youhui-wrap {
    display: flex;
    height: 20px;
    flex-direction: row;
    justify-content: space-between;
    font-size: 20px;
    align-items: center;
    .youhui {
      height: 1px;
      width: 30%;
      background-color: #fff;
      span {
        width: 30%;
        left: 50%;
        transform: translate(-50%);
      }
    }
  }

  h4 {
    text-align: center;
    margin: 20px 0 0 0;
  }
  .van-rate {
    margin: 20px auto;
  }
  .overlay-supports {
    font-size: 18px;
    margin: 20px 0;
  }
}
.main-body::-webkit-scrollbar {
  display: none; /* Chrome Safari */
}
::v-deep .van-tabs__line {
  z-index: -1 !important;
}

.goods-right {
  flex: 1;
  font-size: 16px;
  height: 100%;
  box-sizing: border-box;
  overflow-y: auto;
  img {
    margin-right: 10px;
    border-radius: 5px;
  }
  .goods-conts {
    display: flex;
    padding: 15px 0;
    background-color: #fff;
    img {
      width: 100px;
      height: 100px;
    }
    .goods-Desc {
      width: 100%;

      flex: 1;

      .h4 {
        margin: 2px 0 0 0;
      }
    }
  }
  .fooditem-price {
    font-size: 22px;
    color: #f00;
    font-weight: bold;
  }
  ::v-deep.van-stepper {
    padding-right: 12px;
  }
  .fooditem-p {
    margin-right: 18px;
  }
  .fooditem-sellCount {
    color: #999999;
    font-size: 14px;
  }
}
.main-footer-left {
  width: 70px;
  height: 50px;
  background-color: #222222;
  border-radius: 25px 0 0 25px;
  border-right: 5px solid #fff;
  color: #919191;
  text-align: center;
  font-size: 13px;
  .p1 {
    font-size: 15px;
  }
}
.main-footer-right {
  width: 90px;
  height: 50px;
  background-color: #ffc300;
  border-radius: 0 25px 25px 0;
  text-align: center;
  line-height: 50px;
  font-size: 15px;
  font-weight: bold;
}
.main-footer-middle {
  background-color: #222222;
  .shopcar {
    width: 42px;
    height: 42px;
    background-color: #ffc300;
    border-radius: 21px;
    font-size: 24px;
    margin: 0 8px;
  }
  .shopprice {
    color: #fff;
    font-size: 10px;
    .w {
      font-size: 14px;
    }
    .price {
      font-size: 18px;
      margin: 5px 0;
    }
  }
}
.van-popup--bottom.van-popup--round {
  padding: 15px 15px 50px 15px;
  overflow-y: auto;
}
.goods-right-3 {
  width: 100%;
  height: 18px;
  background-color: #f00;
  position: relative;
}
.child {
  width: 40px;
  height: 40px;
  border-radius: 4px;
  text-align: center;
  line-height: 40px;
}
::v-deep .van-badge {
  min-width: 22px;
  padding: 2px 0px;
  font-size: 14px;
}
.main-footer-middle .shopcar[data-v-4bb18f76] {
  background-color: #999;
}
.main-footer-right[data-v-4bb18f76] {
  background-color: #999;
}
::-webkit-scrollbar {
      display: none;
    }
</style>





